function encodeFileName(filename: string): string {
  // ASCII fallback: 移除非安全字符
  const asciiName = filename.replace(/[^a-zA-Z0-9._-]/g, '_');
  // UTF-8 encoded name for modern browsers
  const utf8Name = encodeURIComponent(filename);
  return `attachment; filename="${asciiName}"; filename*=UTF-8''${utf8Name}`;
}

export { encodeFileName };